package huawei;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class dancipingjie {
    public static void main(String[] args) {

//        String a = "aa";
//        String b = "ab";
//        System.out.println(a.compareTo(b));

        Scanner in = new Scanner(System.in);
        int startIndex = in.nextInt();
        int num = in.nextInt();

        LinkedList<String> array = new LinkedList<>();

        for (int i = 0; i < num; i++){
            array.add(in.next());
        }
        StringBuffer stringBuffer = new StringBuffer();
        System.out.println(appendWord(startIndex, num, array, stringBuffer));
    }

    public static String appendWord(int startIndex, int num, LinkedList<String> array, StringBuffer result){

       if (startIndex >= 0 && startIndex < num){
           String head = array.get(startIndex);

           array.remove(startIndex);

           result.append(head);

           //判断剩余数据中是否有符合条件的数据
           while (true){

               String endChar = getStringEndChar(result.toString());

               //临时数据，用于存放符合条件的数据
               LinkedList<String> ss = new LinkedList<>();
               for (int i = 0; i < array.size(); i++){
                    if (endChar.equals(getStringStartChar(array.get(i)))){
                        ss.add(array.get(i));
                    }
               }

               if (ss.size() <= 0){
                   return result.toString();
               }

               int maxLength = 1;
               int maxLengthIndex = 0;


               /**
                * 1.首先取长度最长的单词
                * 2.如果有多个长度最长的，则取字典序最小的单词
                */
               for (int k = 0; k < ss.size(); k++){
                   int currtentLength = ss.get(k).length();
                   if (currtentLength > maxLength){
                       maxLengthIndex = k;
                       maxLength = currtentLength;
                   }

                   if (currtentLength == maxLength){
                       if (ss.get(maxLengthIndex).compareTo(ss.get(k)) > 0){
                           maxLengthIndex = k;
                       }
                   }
               }

               result.append(ss.get(maxLengthIndex));

               array.remove(ss.get(maxLengthIndex));
           }
       }

        return null;
    }

    public static String getStringEndChar(String text){
        char n = text.charAt(text.length() - 1);
        return n + "";
    }

    public static String getStringStartChar(String text){
        char n = text.charAt(0);
        return n + "";
    }


}
